﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Xml;

namespace matrix_screen_pc_prog
{
    class Services : INotifyPropertyChanged
    {
        string m_str_service;
        UInt32 m_color = 1;
        int m_sound = 70;

        int m_key_id;
        public int KeyId
        {
            get { return m_key_id; }
            set
            {
                if (m_key_id != value)
                {
                    m_key_id = value;
                    RaiseOnPropertyChanged("KeyId");
                }
            }
        }

        public string Service
        {
            get { return m_str_service; }
            set
            {
                if(m_str_service != value)
                {
                    m_str_service = value;
                    RaiseOnPropertyChanged("Service");
                }
            }
        }

        public UInt32 Color
        {
            get { return m_color; }
            set
            {
                if(m_color != value)
                {
                    m_color = value;
                    RaiseOnPropertyChanged("Color");
                }
            }
        }

        public int Sound
        {
            get { return m_sound; }
            set
            {
                if (m_sound != value)
                {
                    m_sound = value;
                    RaiseOnPropertyChanged("Sound");
                }
            }
        }


        public Services(XmlElement xElement)
        {
            if(xElement == null)
            {
                
            }
            else
            {
                m_str_service = xElement.GetAttribute("Name");
                if(xElement.GetAttribute("Color").Length > 0)
                    UInt32.TryParse(xElement.GetAttribute("Color"), out m_color);
                if(xElement.GetAttribute("Sound").Length > 0)
                    int.TryParse(xElement.GetAttribute("Sound"), out m_sound);
                if (xElement.GetAttribute("Key").Length > 0)
                    int.TryParse(xElement.GetAttribute("Key"), out m_key_id);
            }
        }
        public Services()
        {

        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void RaiseOnPropertyChanged(String propertyName)
        {
            if (null != this.PropertyChanged)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
